<?php echo $header; ?>
	<div class="alert-wrap">
	  	<div class="alert-prvatesetting alert-position">
	  	</div>
	  </div>
	<div class="container in-wrap">	
      <div class="row">
        <div class="col-md-10 col-md-offset-1">
          <h1 class="text-center"><?php echo $maincontent; ?></h1>
        </div>
      </div>
      <form class="form-horizontal" id="prvatesetting-form">
      		<h3 class="text-center">修改昵称</h3>
	     	<div class="form-group from-margin-top has-feedback">
	     		<label for="" class="control-label col-md-2 col-md-offset-1">昵称设置</label>
	     		<div class="col-md-6">
	     			<input type="text" name="nickname-setting" id="nickname-setting" class="form-control" placeholder="昵称" value="<?php echo $nickname; ?>">
	     			<p class="form-control nickname-p"><?php echo $nickname; ?></p>
	     			<span class="glyphicon glyphicon-pencil form-control-feedback little-icon nickname-pencil"></span>
	     		</div>
	     	</div>
	     	<h3 class="text-center">修改密码</h3>
	     	<div class="form-group has-feedback from-margin-top">
	     		<label for="" class="control-label col-md-2 col-md-offset-1">原密码</label>
	     		<div class="col-md-6">
	     			<input type="password" name="old-password" id="old-password" class="form-control" placeholder="原密码">
	     			<span class="glyphicon glyphicon-eye-open form-control-feedback little-icon"></span>
	     			<span class="glyphicon  form-control-feedback little-icon icon-right" id="old-password-loading"><img src="admin\view\image\loading\sixnew.gif" class="img-responsive img-center" alt="Responsive image"></span>
	     			<span class="glyphicon glyphicon-ok form-control-feedback little-icon icon-green icon-right-icon" id="old-password-ok"></span>
	     			<span class="glyphicon glyphicon-remove form-control-feedback little-icon icon-red icon-right-icon" id="old-password-wrong"></span>
	     		</div>
	     	</div>
	     	<div class="form-group has-feedback from-margin-top">
	     		<label for="" class="control-label col-md-2 col-md-offset-1">新密码</label>
	     		<div class="col-md-6">
	     			<input type="password" name="new-password" id="private-new-password" class="form-control" placeholder="新密码">
	     			<span class="glyphicon glyphicon-eye-open form-control-feedback little-icon"></span>
	     		</div>
	     	</div>
	     	<div class="form-group has-feedback from-margin-top">
	     		<label for="" class="control-label col-md-2 col-md-offset-1">重复密码</label>
	     		<div class="col-md-6">
	     			<input type="password" name="re-new-password" id="private-re-new-password" class="form-control" placeholder="重复密码">
	     			<span class="glyphicon glyphicon-eye-open form-control-feedback little-icon"></span>
	     		</div>
	     	</div>
	     	<div class="form-group from-margin-top">
	     			<div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3">
	     				<a href="javascript:void(0);" class="btn btn-primary create-btn" id="privatesetting-submit-password">
	     					提交
	     				</a>
	     				<button type="reset" class="btn btn-primary create-btn" id="prvatesetting-reset">重置</button>
	     			</div>
	     	</div>
     	</form>
	</div>



<?php echo $footerin;?>
<script>
	$(function(){
		//点眼睛显示密码
		var $eye = $(".glyphicon-eye-open");
		var $targets = $("#old-password,#private-new-password,#private-re-new-password");
		var $alert_prvatesetting = $(".alert-prvatesetting");
		var $namesetting = $("#nickname-setting");
		var $old_p_target = $("#old-password");
		var target_first_password = "#private-new-password";
		var target_re_password = "#private-re-new-password";
		var old_password_isok = false;
		eyetoggle($eye,$targets);
		//昵称修改切换
		$(".nickname-pencil").on("click",function(){
			$(this).fadeOut();
			$(".nickname-p").css("display","none");
			$namesetting.css("display","block").focus();
		});
		//提交昵称
		$namesetting.on("keydown",function(event){
			if (event.keyCode == "13") {
					submitNickname($namesetting,$alert_prvatesetting);
				}
		}).on("blur",function(){
			submitNickname($namesetting,$alert_prvatesetting);
		});
		//原密码验证
		$old_p_target.on("blur",function(){

			if(!old_password_vel($(this),$alert_prvatesetting)){
				return false;
			}else{
				old_password_isok = true;
			}
		});
		//密码验证
		$(target_first_password+","+target_re_password).blur(function(){
			var password = $(target_first_password).val();
			var repassword = $(target_re_password).val();
			if(!password_vel(password,repassword,$alert_prvatesetting,$alert_prvatesetting)){
				return false;
			};
		})
		
		//点击修改密码
		$("#privatesetting-submit-password").on("click",function(){
			if(!old_password_isok){
				return false;
			};
			var password = $(target_first_password).val();
			var repassword = $(target_re_password).val();
			if(!password_vel(password,repassword,$alert_prvatesetting,$alert_prvatesetting)){
				return false;
			};
			$.ajax({
				type:"POST",
				dataType:"json",
				url:"<?php echo $resetpasswordurl; ?>",
				data:{password:password},
				beforeSend: function() {
	                	alert2000($alert_prvatesetting,"正在修改密码请稍等!");
	                },
				success: function (data){
					if (data === 1){
						$("#old-password-ok,#old-password-wrong").css("display","none");
						alert2000($alert_prvatesetting,"密码修改成功!");
						$("#prvatesetting-form")[0].reset();
					} else if(data === 0){
						alert2000($alert_prvatesetting,"密码修改失败，请重试!");
					} else {
						alert2000($alert_prvatesetting,data);
					}
				}
			});
		})
		//重置原密码验证小图标
		$("#prvatesetting-reset").on("click",function(){
			$("#old-password-ok,#old-password-wrong").css("display","none");
		});
	})
	function submitNickname($target,$alerttarget){
		$target.css("display","none");
		$(".nickname-p").css("display","block").html($target.val());
		$(".nickname-pencil").fadeIn();
		var oldnickname = $(".header-nickname").html();
		var nickname = $target.val();
		try{
			if (nickname == "") {
				throw "昵称不能为空";
			}
			if (nickname == oldnickname) {
				throw "昵称未改变";
			}
			if (nickname.length > 7){
				throw "昵称长度不能大于7字符";
			}
		}
		catch(e) {
			alert2000($alerttarget,e);
			$(".nickname-p").html(oldnickname);
			return false;
		}
		$.ajax({
	        type:"POST",
	        dataType:"json",
	        url:"<?php echo $editnicknameurl; ?>",
	        data:{nickname:nickname},
	        beforeSend: function() {
	            alert2000($alerttarget,"数据正在加载……");
	        },
	        success: function (data){
	        	$(".header-nickname").html(nickname);
	        	alert2000($alerttarget,data);
	        }
        })
	}
	function old_password_vel($target,$alerttarget){
		var mybool="bool";
		var old_password = $target.val();
			if(!password_vel(old_password,false,$alerttarget)){
				mybool = false;
				return mybool;
			}
			$.ajax({
                    type:"POST",
                    dataType:"json",
                    url:"<?php echo $oldpasswordvelurl; ?>",
                    data:{oldpassword:old_password},
                    beforeSend: function() {
                    	$("#old-password-ok,#old-password-wrong").css("display","none");
                        $("#old-password-loading").css("display","block");
                    },
                    success: function (data){
                    	$("#old-password-loading").css("display","none");
                    	if(data){
                    		$("#old-password-ok").css("display","block");
                    		mybool = true;
                    	}else{
                    		$("#old-password-wrong").css("display","block");
                    		mybool = false;
                    	}
                    }
            })
           	return mybool;
		}
</script>
<?php echo $footer;?>